package com.gemfire.onlineretailer.domain;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.gemstone.gemfire.DataSerializable;
import com.gemstone.gemfire.DataSerializer;

public class ShoppingCart implements DataSerializable {

	private long orderId;
	private String orderNumber;
	private Date orderdate;
	
	private List<Item> purchasedItems;
	private double totalCost;
	private float tax;

	@Override
	public void fromData(DataInput in) throws IOException,
			ClassNotFoundException {
		
		this.orderId = in.readLong();
		this.orderNumber = in.readUTF();
		this.orderdate = DataSerializer.readDate(in);
		this.totalCost = in.readDouble();
		this.tax = in.readFloat();
		
		List<Item> items = new ArrayList<Item>();
		
	}

	@Override
	public void toData(DataOutput out) throws IOException {
		out.writeLong(this.orderId);
		out.writeUTF(this.orderNumber);
		DataSerializer.writeDate(this.orderdate, out);
		out.writeDouble(this.totalCost);
		out.writeFloat(this.tax);
		for (Item item : purchasedItems){
			if (item instanceof Book){
				DataSerializer.writeObject((Book) (item), out);
			}
			if (item instanceof Clothing){
				DataSerializer.writeObject((Clothing) (item), out);
			}
			if (item instanceof Electronics){
				DataSerializer.writeObject((Electronics) (item), out);
			}
			if (item instanceof Disk){
				DataSerializer.writeObject((Disk) (item), out);
			}
			if (item instanceof Furniture){
				DataSerializer.writeObject((Furniture) (item), out);
			}
		}
	}
	
	
		  
}
